<template>
	<view class="meractapplication">
		<view class="list">
			<view class="item">
				<view class="item_title">商户UID</view>
				<view class="item_text">
					<input type="text" placeholder="请输入商户UID" v-model="shopuid" />
				</view>
			</view>
			<view class="item">
				<view class="item_title">门店名称</view>
				<view class="item_text">
					<input type="text" v-model="shopName" disabled="true" />
				</view>
				<image v-if="shopinfoArr.length>1" src="../../static/img/my_back.png" @click="show = true"></image>
			</view>
			<view class="item">
				<view class="item_title">门店ID</view>
				<view class="item_text">
					<input type="text" v-model="shopid" disabled="true" />
				</view>
			</view>
			<view class="item" v-show="!(real_rate==0)">
				<view class="item_title">基础支付费率<br>(万分数)</view>
				<view class="item_text">
					<input type="text" v-model="rate" placeholder="请输入基础支付费率(万分数)" />
				</view>
			</view>
			<view class="item redfont" v-show="!(real_rate==0)">
				注：针对非U品的基础支付（堂食、台卡）订单，申请商户费率调整，区间为23-300（万分数）。
			</view>
			<view class="item redfont" v-show="real_rate==0">
				注：当前商户为B政策商户不可修改基础支付费率。
			</view>
		</view>
		
		<button type="primary" @click="shoprateaddFun()">提交</button>
		
		<!-- 选择门店弹窗 -->
		<u-popup ref="popup" v-model="show" mode="center" border-radius="14">
			<view class="zlpopup">
				<view class="zlpopup_item" v-for="(item,index) in shopinfoArr" @click="selectShop(index)">
					{{item.shop_name}}
				</view>
			</view>
		</u-popup>
		<!-- 运营数据弹窗 -->
		<!-- <uni-popup ref="popup" :show="true" type="center">
			<view class="zlpopup">
				<view class="zlpopup_item" v-for="(item,index) in shopinfoArr" @click="selectShop(index)">
					{{item.shop_name}}
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	import { shopinfo,shoprateadd } from "../../api/index.js"
	// import uniPopup from '@/components/uni-popup/uni-popup.vue';
	export default {
		data() {
			return {
				show:false,//控制弹窗是否显示
				
				shopuid:"",
				shopName:"",
				shopid:"",
				timeout:null,
				shopinfoArr:"",
				rate:"",
				real_rate:1 //商户政策类型 0=B政策，其他的=A政策,默认A政策
			}
		},
		onLoad:function(){
			
		},
		methods: {
			//防抖
			debounce:function(){
				let that = this;
				if(that.timeout !== null){
					clearTimeout(that.timeout)
				};
				that.timeout = setTimeout(function(){
					that.getShopinfo()
				}, 1000);
			},
			getShopinfo:function(){
				let that = this;
				shopinfo({
					uid:that.shopuid
				}).then((res) => {
					console.log(res)
					if(res.code == 0){
						that.shopinfoArr = res.data;
						that.shopName = res.data[0].shop_name;
						that.shopid = res.data[0].id;
						that.real_rate = res.data[0].real_rate;
					}
				}).catch((e) => {
					console.log(e);
				})
			},
			shoprateaddFun:function(){
				let that = this;
				if(that.rate>300||that.rate<23){
					uni.showToast({
						icon:'none',
						title:'费率区间为23-300'
					})
					return ;
				}
				shoprateadd({
					id:that.shopid,
					rate:that.rate
				}).then((res) => {
					if(res.code == 0){ //申请成功则跳转到列表
						// alert(res.msg)
						uni.showModal({
							title:'提示',
							content: res.msg,
							complete:function(){
								uni.navigateBack({})
							}
						})
						// uni.navigateTo({
						// 	url:'../merchantact/merchantact'
						// })
					}
				}).catch((e) => {
					console.log(e);
				})
			},
			// open:function(){
			// 	this.$refs.popup.open();
			// },
			selectShop:function(index){
				this.shopName = this.shopinfoArr[index].shop_name;
				this.shopid = this.shopinfoArr[index].id;
				this.real_rate = this.shopinfoArr[index].real_rate;
				// this.$refs.popup.close();
				this.show = false;
			}
		},
		watch:{
			shopuid:function(){
				this.debounce()
			},
			//监听当前政策类型的变化，假如当前是B政策则动态赋值当前费率为38
			real_rate:function(){
				this.real_rate==0?this.rate=38:this.rate=''
			}
		},
		// components:{
		// 	uniPopup
		// }
	}
</script>

<style lang="scss" scoped>
	.meractapplication{
		// height: 100%;
		// background-color: #F5F5F5;
		font-size: $uni-font-size-base;
		border-top: 1rpx solid $uni-solid-color;
		.list{
			background-color: #FFFFFF;
			padding: 0 30rpx;
			margin-bottom: 30rpx;
			.item{
				display: flex;
				align-items: center;
				padding: 30rpx 0;
				border-bottom: 1rpx solid $uni-solid-color;
				position: relative;
				.item_title{
					color: #666666;
					width: 30%;
				}
				.item_text{
					width: 60%;
					input{
						width: 100%;
						font-size: $uni-font-size-base;
					}
				}
				image{
					position: absolute;
					right: 0;
					top: 30rpx;
					width: 40rpx;
					height: 40rpx;
				}
				&.redfont{
					font-size: $uni-font-size-sm;
				}
			}
		}
		button{
			width: 80%;
			font-size: $uni-font-size-lg;
			margin-top: 100rpx;
		}
		.zlpopup{
			background-color: #FFFFFF;
			margin: 0 auto;
			border-radius: $uni-border-radius-lg;
			font-size: $uni-font-size-base;
			.zlpopup_item{
				padding: 30rpx;
				min-width: 200rpx;
				text-align: center;
			}
		}
	}
</style>
